
#include <iostream>
#include "SDL/SDL.h"

using namespace std;

SDL_Event event;

SDL_Joystick *stick  = NULL;

int main(int argc, char* args[]){
	
	SDL_Init(SDL_INIT_EVERYTHING);

    stick = SDL_JoystickOpen(0);

	int loop = true;

	Sint16	LeftX, 
			LeftY, 
			RightX, 
			RightY, 
			Triggers;

	Uint8	Hat;

	Uint8	butA, 
			butB, 
			butX, 
			butY, 
			butLeft, 
			butRight, 
			butStart, 
			butSelect,
			butLeftStick,
			butRightStick;

	while (loop){

		SDL_JoystickUpdate();

		LeftX  = SDL_JoystickGetAxis(stick, 0);
		LeftY  = SDL_JoystickGetAxis(stick, 1);
		RightX = SDL_JoystickGetAxis(stick, 3);
		RightY = SDL_JoystickGetAxis(stick, 4);

		Triggers = SDL_JoystickGetAxis(stick, 2);

		Hat = SDL_JoystickGetHat(stick, 0);

		if (Hat == SDL_HAT_UP)
			cout << "SDL_HAT_UP" << endl;
		
		else if (Hat == SDL_HAT_DOWN)
			cout << "SDL_HAT_DOWN" << endl;
		
		else if (Hat == SDL_HAT_LEFTUP)
			cout << "SDL_HAT_LEFTUP" << endl;

		else if (Hat == SDL_HAT_LEFT)
			cout << "SDL_HAT_LEFT" << endl;

		else if (Hat == SDL_HAT_LEFTDOWN)
			cout << "SDL_HAT_LEFTDOWN" << endl;		

		else if (Hat == SDL_HAT_RIGHTUP)
			cout << "SDL_HAT_RIGHTUP" << endl;

		else if (Hat == SDL_HAT_RIGHT)
			cout << "SDL_HAT_RIGHT" << endl;

		else if (Hat == SDL_HAT_RIGHTDOWN)
			cout << "SDL_HAT_RIGHTDOWN" << endl;

		butA = SDL_JoystickGetButton(stick, 0);
		butB = SDL_JoystickGetButton(stick, 1);
		butX = SDL_JoystickGetButton(stick, 2);
		butY = SDL_JoystickGetButton(stick, 3);

		butLeft  = SDL_JoystickGetButton(stick, 4);
		butRight = SDL_JoystickGetButton(stick, 5);
		
		butStart  = SDL_JoystickGetButton(stick, 6);
		butSelect = SDL_JoystickGetButton(stick, 7);

		butLeftStick  = SDL_JoystickGetButton(stick, 8);
		butRightStick = SDL_JoystickGetButton(stick, 9);

		if (butA)
			cout << "Button A pressed" << endl;

		if (butB)
			cout << "Button B pressed" << endl;

		if (butX)
			cout << "Button X pressed" << endl;

		if (butY)
			cout << "Button Y pressed" << endl;

		if (butLeft)
			cout << "Left Trigger Button pressed" << endl;

		if (butStart)
			cout << "butStart Button pressed" << endl;

		if (butSelect)
			cout << "butSelect Button pressed" << endl;

		if (butRight)
			cout << "Right Trigger Button pressed" << endl;

		if (butLeftStick)
			cout << "butLeftStick Button pressed" << endl;

		if (butRightStick)
			cout << "butRightStick Button pressed" << endl;

		cout << LeftX << "\t" << LeftY << "\t" << RightX << "\t" << RightY << "\t" << Triggers << endl;
	}

	return 0;
}